vscodeですかね?
ひとまず赤波線をマウスオーバーした時に、ポップアップか何かが出ませんでしょうか?
あと、main.cppのコンパイルはできますか?
コンパイルエラーになるようであれば、そのエラーメッセージには何が書かれていますか?
競プロのための環境構築がうまくいきません
解決したいこと
競プロに興味を持ち環境構築を始めたのですが、#include <bits/stdc++から永遠に赤線が取れません。
様々なサイトを参考にしたのですが、どのサイトも少しずつ違うことが書かれておいり、何が原因かもはっきりしません。
発生している問題・エラー
main.cpp
#include <bits/stdc++.h>
//ここにずっと赤い波線がで続けています
using namespace std;
int main(){
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < N - 1; i++) cout << A[i] * A[i + 1] << " ";
}
現在の状況
ディレクトリ
□ root
└□ Users
└□ {username}
└□ cp
├□ .vscode
│├○ c_cpp_properties.json
│├○ launch.json
│├○ settings.json
│└○ tasks.json
├□ atcoder
│├○ all
│├○ convolution
│:
│├○ twosat
│└○ twosat.hpp
├○ expander.py
├○ main.cpp
└○ main.py
各jsonファイル
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/atcoder",
"/usr/local/include/**",
"/usr/local/include/bits"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/local/bin/g++-13",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
launch.json
{
"configurations": [
{
"name": "C/C++: g++-13 build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++-13 build active file"
}
],
"version": "2.0.0"
}
settings.json
//本当に何も書いてないです。
{
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-13 build active file",
"command": "/usr/local/bin/g++-13",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I",
"."
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++-13 アクティブなファイルのビルド",
"command": "/usr/local/bin/g++-13",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I",
"."
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "デバッガーによって生成されたタスク。"
}
],
"version": "2.0.0"
}
自分で試したこと
homebrewのインストール
homebrewは見当たらないが、brew install gccは機能する状況
gccのインストール
上記の通りbrew install gccでgcc-13、g++-13を/usr/local/binへ入れることはできた。
which g++-13
/usr/local/bin/g++-13
which gcc-13
/usr/local/bin/gcc-13
シンボリックリンク
実行したコマンド
ls -s /usr/local/bin/gcc-13 /usr/local/bin/gcc
いまだにgccとgccのふりをしたClangの見分け方がわからないがおそらくうまくいっていない。現在gccと実行すると下のようになる。
/usr/local/bin/gcc-13
gcc-13: fatal error: no input files
compilation terminated.
gcc
gcc: fatal error: no input files
compilation terminated.
情報の過不足等流かと思いますがよろしくお願いします
2Answer
Comments
@c0b211003a
Questionerご回答ありがとうございます
ポップアップとエラーです
% /usr/local/bin/gcc-13 /Users/{username}/cp/main.cpp In file included from /usr/local/Cellar/gcc/13.2.0/include/c++/13/x86_64-apple-darwin23/bits/stdc++.h:33, from /Users/{username}/cp/main.cpp:1: /usr/local/Cellar/gcc/13.2.0/include/c++/13/cassert:44:10: fatal error: assert.h: No such file or directory 44 | #include <assert.h> | ^~~~~~~~~~ compilation terminated.
% /usr/local/bin/g++-13 /Users/{username}/cp/main.cpp In file included from /usr/local/Cellar/gcc/13.2.0/include/c++/13/x86_64-apple-darwin23/bits/stdc++.h:33, from /Users/{username}/cp/main.cpp:1: /usr/local/Cellar/gcc/13.2.0/include/c++/13/cassert:44:10: fatal error: assert.h: No such file or directory 44 | #include <assert.h> | ^~~~~~~~~~ compilation terminated.
コンパイルってこれであってますか?
こんな感じです!
システムヘッダーの一部が見つからないようですね。
おそらくincludePathに不足があるのだと思います。こちの記事を参考に、不足しているパスを探してみてはどうでしょう。
自分はc++-13
を使っています。
brew install gcc
でインストールしたディレクトリのbinにいると思います(g++-13と同じディレクトリ)。
それを/opt/homebrew/bin/c++-13
にシンボリックリンクして、
さらにalias gcc="c++-13"
で、gcc
としています。
(上のmain.cppをgcc main.cpp
でコンパイルできました)
% which gcc
gcc: aliased to c++-13
% which c++-13
/opt/homebrew/bin/c++-13
% c++-13 -v #gcc -v も同じ
Using built-in specs.
COLLECT_GCC=c++-13
(中略)
gcc version 13.2.0 (Homebrew GCC 13.2.0)
元々の gcc が、clang です。
% unalias gcc
% which gcc
/usr/bin/gcc
% gcc -v
Apple clang version 15.0.0 (clang-1500.3.9.4)
Comments
@c0b211003a
Questioner返信ありがとうございます
$ which gcc /usr/local/bin/gcc $ which c++-13 /usr/local/bin/c++-13 $ gcc -v Using built-in specs. COLLECT_GCC=c++-13 (中略) gcc version 13.2.0 (Homebrew GCC 13.2.0)
コンパイラ自体はうまく設定できていると思います。しかし、うまくいきませんでした。gcc、c++で試しにコンパイルしてみたのですが失敗しました。includeが失敗しているのでもしかしたらコンパイルとは別の部分かもしれません
$ gcc main.cpp In file included from /usr/local/Cellar/gcc/13.2.0/include/c++/13/x86_64-apple-darwin23/bits/stdc++.h:33, from main.cpp:1: /usr/local/Cellar/gcc/13.2.0/include/c++/13/cassert:44:10: fatal error: assert.h: No such file or directory 44 | #include <assert.h> | ^~~~~~~~~~ compilation terminated.
$ c++-13 main.cpp In file included from /usr/local/Cellar/gcc/13.2.0/include/c++/13/x86_64-apple-darwin23/bits/stdc++.h:33, from main.cpp:1: /usr/local/Cellar/gcc/13.2.0/include/c++/13/cassert:44:10: fatal error: assert.h: No such file or directory 44 | #include <assert.h> | ^~~~~~~~~~ compilation terminated.
include pathに対して、何かした覚えはありません。
gcc -v main.cpp
の結果を貼っておくので、参考にしてください。Downloads % gcc -v main.cpp Using built-in specs. COLLECT_GCC=c++-13 COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/13/lto-wrapper Target: aarch64-apple-darwin23 Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk --with-ld=/Library/Developer/CommandLineTools/usr/bin/ld-classic Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (Homebrew GCC 13.2.0) COLLECT_GCC_OPTIONS='-v' '-mmacosx-version-min=14.0.0' '-asm_macosx_version_min=14.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a-' /opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/13/cc1plus -quiet -v -iprefix /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/ -D__DYNAMIC__ main.cpp -fPIC -quiet -dumpdir a- -dumpbase main.cpp -dumpbase-ext .cpp -mmacosx-version-min=14.0.0 -mlittle-endian -mabi=lp64 -version -o /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccpg4XRa.s GNU C++17 (Homebrew GCC 13.2.0) version 13.2.0 (aarch64-apple-darwin23) compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.2.0-p12, MPC version 1.3.1, isl version isl-0.26-GMP warning: GMP header version 6.2.1 differs from library version 6.3.0. warning: MPFR header version 4.2.0-p12 differs from library version 4.2.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../aarch64-apple-darwin23/include" ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13" ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13/aarch64-apple-darwin23" ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13/backward" ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/include" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include" ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/include-fixed" ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../aarch64-apple-darwin23/include" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/Library/Frameworks" #include "..." search starts here: #include <...> search starts here: /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13 /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13/aarch64-apple-darwin23 /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../../../../include/c++/13/backward /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/include /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/include-fixed /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks End of search list. Compiler executable checksum: 680f8e0ef035e7bc969098d106286225 COLLECT_GCC_OPTIONS='-v' '-mmacosx-version-min=14.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a-' as -arch arm64 -v -mmacosx-version-min=14.0 -o /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccjdcsls.o /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccpg4XRa.s Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.4.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple arm64-apple-macosx14.0.0 -filetype obj -main-file-name ccpg4XRa.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +crc -target-feature +lse -target-feature +rdm -target-feature +crypto -target-feature +dotprod -target-feature +fp-armv8 -target-feature +neon -target-feature +fp16fml -target-feature +ras -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -fdebug-compilation-dir=/Users/USERNAME/Downloads -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.3.9.4)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccjdcsls.o /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccpg4XRa.s COMPILER_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/ LIBRARY_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../../ COLLECT_GCC_OPTIONS='-v' '-mmacosx-version-min=14.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a.' /opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/13/collect2 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ -dynamic -arch arm64 -platform_version macos 14.0.0 0.0 -o a.out -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13 -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/13/../../.. /var/folders/1x/rmf3qp1j04n6r2zzb23r1jy40000gn/T//ccjdcsls.o -lstdc++ -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/13 -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current Downloads %
@c0b211003a
Questioner色々試してるのですがどうしてもダメです...
今の所標準ライブラリがincludeできていない説が濃厚だと思うのですが、特に標準ライブラリがXcode周りのディレクトリにあるせいで、変な挙動になっているのかな?と思っています。
Xcodeはダウンロードしているでしょうか?
Xcodeもインストールしてあります。
ターミナルで
brew info gcc
を実行した結果を貼ってもらえませんか?$ brew info gcc ==> gcc: stable 13.2.0 (bottled), HEAD GNU compiler collection https://gcc.gnu.org/ Installed /opt/homebrew/Cellar/gcc/13.2.0 (1,489 files, 382.6MB) * Poured from bottle using the formulae.brew.sh API on 2023-11-02 at 14:41:02 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/gcc.rb License: GPL-3.0-or-later with GCC-exception-3.1 ==> Dependencies Required: gmp ✔, isl ✔, libmpc ✔, mpfr ✔, zstd ✔ ==> Options --HEAD Install HEAD version ==> Analytics install: 108,887 (30 days), 327,228 (90 days), 1,271,645 (365 days) install-on-request: 36,222 (30 days), 109,099 (90 days), 563,382 (365 days) build-error: 3,655 (30 days)